package com.allwees.bs.c.module.share.req;

import com.allwees.bs.core.model.share.bo.ShareBo;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.core.common.util.UuidUtil;
import com.allwees.core.common.util.reflect.PojoUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 分享动作Req
 *
 * @author yangylsky
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ShareGenReq extends ShareEventReq {
    private String uuid;

    /**
     * 分享者uuid
     */
    private String sharerUuid;

    private String bsKey;

    @Override
    public ValidateItem[] getValidateItems() {
        return ArrayUtils.addAll(
                new ValidateItem[]{
                        new ValidateItem(StringUtils.isBlank(bsKey), "bsKey can not be empty"),
                        new ValidateItem(platform == null, "platform can not be a null"),
                        new ValidateItem(type == null, "type can not be a null")
                },
                super.getValidateItems()
        );
    }

    @Override
    protected Object[] signValues() {
        return new Object[]{bsKey, platform.name(), type.name(), getTime().getTime()};
    }

    @Override
    protected String signSeparator() {
        return platform.isApp() ? "_SA_" : "_SW_";
    }

    public ShareBo toShareBo() {
        ShareBo dto = PojoUtil.copy(new ShareBo(), this);
        if (StringUtils.isBlank(dto.getUuid())) {
            dto.setUuid(UuidUtil.generate());
        }
        return dto;
    }
}
